<!DOCTYPE html>
<html>
<head>
    <title>录入住院信息</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/style.css"/>
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <!--    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>-->
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>


    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
        $(function () {
            $('#backid').click(function () {
                window.location.href = "index.html";
            });
        });
    </script>
</head>
<body>
<form class="definewidth m20" id="myForm">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">病历号</td>
            <td><input type="text" id="hosR_id" name="hosR_id" placeholder="输入病历号回车自动带出挂号人信息"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">姓名</td>
            <td><input type="text" name="hosR_name" placeholder="姓名" id="hosR_name"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">证件类型</td>
            <td>身份证</td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">证件号</td>
            <td><input type="text" id="hosR_idCar" name="hosR_idCar" placeholder="身份证号"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">社保号</td>
            <td><input type="text" id="hosR_medical" name="hosR_medical" placeholder="社保号"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">联系电话</td>
            <td><input type="text" id="hosR_phone" name="hosR_phone" placeholder="联系电话"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">是否自费</td>
            <td>
                <input type="radio" id="hosR_selfPrice1" name="hosR_selfPrice" value="1" checked/>是&nbsp;&nbsp;&nbsp;
                <input type="radio" id="hosR_selfPrice2" name="hosR_selfPrice" value="0"/>否
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">性别</td>
            <td>
                <input type="radio" id="nan" name="hosR_sex" value="1" checked/>男&nbsp;&nbsp;&nbsp;
                <input type="radio" id="nv" name="hosR_sex" value="0"/>女
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">年龄</td>
            <td><input type="number" id="hosR_age" name="hosR_age"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">初复诊</td>
            <td>
                <input type="radio" name="hosR_lookDoctor" id="c1" value="0"/>初诊
                <input type="radio" name="hosR_lookDoctor" id="c2" value="1"/>复诊
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">所挂科室</td>
            <td>
                <div id="deptName"></div>
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">指定医生</td>
            <td>
                <select id="doctorId" name="doctorId">
                    <option>请选择挂号医生</option>
                </select>
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">备注</td>
            <td><input type="text" id="hosR_remark" name="hosR_remark" placeholder="备注"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">护理</td>
            <td><input type="text" id="beH_nursePeople" name="beH_nursePeople" placeholder="护理人员"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">床位号</td>
            <td><input type="text" id="beH_patBed" name="beH_patBed" placeholder="床位号"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">缴费押金</td>
            <td><input type="text" id="newDeposit" name="newDeposit"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">病情</td>
            <td><textarea id="beH_illness" name="beH_illness" placeholder="请输入病情"></textarea></td>
        </tr>
        <tr>
            <td colspan="2">
                <center>
                    <input class="btn btn-primary" type="button" id="btnAdd"   value="保存" onclick="update()"> &nbsp;&nbsp;<button
                        type="button" class="btn btn-success" name="backid" id="backid">返回列表
                </button>
                </center>
            </td>
        </tr>
    </table>
</form>
<script>

    $(document).keydown(function (event) {
        let id = $("#hosR_id").val();
        if (event.keyCode == 13) {
            $.ajax({
                type: "get",
                url: "/HMC/findByID",
                data: {"id": id},
                dataType: "json",
                success: function (vo) {
                    let data = vo.obj;
                    let hosR_state = data.status;
                    if (hosR_state==1){
                        alert("该病人已经住院")
                        location.reload();
                        $("#btnAdd").attr("disabled",true)
                    }
                    else {
                        $("#btnAdd").attr("disabled",false)
                        $("#hosR_name").val(data.registerName);
                        $("#hosR_idCar").val(data.idNumber);
                        $("#hosR_medical").val(data.medicalNumber);
                        $("#hosR_phone").val(data.phone);
                        data.selfPrice == 1 ? $("#hosR_selfPrice1").prop('checked', true) : $("#hosR_selfPrice2").prop('checked', true);
                        data.sex == 1 ? $("#nan").prop('checked', true) : $("#nv").prop('checked', true);
                        $("#hosR_age").val(data.age);
                        data.lookDoctor == 0 ? $("#c1").prop('checked', true) : $("#c2").prop('checked', true);
                        data.department == 0 ? document.getElementById('deptName').innerHTML = "该病人没有科室" : document.getElementById('deptName').innerHTML = data.dept.deptName;
                        findDoctor(data.doctorId);
                        $("#doctorId").val(data.doctorId).prop('selected', true);
                        $("#hosR_remark").val(data.note);
                        $("#beH_nursePeople").val(data.hospital.nursePeople);
                        $("#beH_patBed").val(data.hospital.bedNumber);
                        $("#beH_illness").val(data.hospital.illness);
                        // data.note==null?$("#hosR_remark").val(""):$("#hosR_remark").val(data.note);
                        // data.hospital.nursePeople==null?$("#beH_nursePeople").val(""):$("#beH_nursePeople").val(data.hospital.nursePeople);
                        // data.hospital.bedNumber==0?$("#beH_patBed").val(""):$("#beH_patBed").val(data.hospital.bedNumber);
                        // data.hospital.illness==null?$("#beH_illness").val(""):$("#beH_illness").val(data.hospital.illness);
                    }
                }
            })
        }
    });

    function findDoctor(result) {
        $.ajax({
            type: "GET",
            url: "/Doctor/findDoctorAll",
            dataType: "json",
            success: function (vo) {
                let data = vo.list;
                let str = "";
                for (let i = 0; i < data.length; i++) {
                    if (result == data[i].id) {
                        str += "<option selected='selected' value=\" " + data[i].id + "\">" + data[i].doctorName + "</option>\n"
                    } else {
                        str += "<option value=\" " + data[i].id + "\">" + data[i].doctorName + "</option>\n"
                    }

                }
                $("#doctorId").html(str);

            },
        })

    }

    function update() {
        $.ajax({
            url: "/HMC/updateForAdd",
            type: "POST",
            dataType: 'json',
            data: $('#myForm').serialize(),
            error: function (request) {
                alert("添加失败")
            },
            success: function (data) {
                //接收后台返回的结果
                alert("添加成功");
                window.location.href="index.html";
            }
        });
    }
</script>
</body>
</html>